<template>
    <div>
        <hd-tab :tabs="tabs"/>
        <el-form ref="form" :inline="false" :model="form" disabled label-width="80px" size="normal">
            <el-card :body-style="{ padding: '20px' }" shadow="never">
                <div slot="header">
                    会员管理
                </div>
                <el-form-item label="名称">
                    <el-input v-model="form.name" placeholder="简介说明"></el-input>
                    <hd-error name="name"/>
                </el-form-item>
                <el-form-item label="联盟会员">
                    <el-radio-group v-model="form.member" placeholder="联盟会员">
                        <el-radio :label=1>是</el-radio>
                        <el-radio :label=0>否</el-radio>
                    </el-radio-group>
                    <hd-error name="member"/>
                </el-form-item>
                <el-form-item label="手机号">
                    <el-input v-model="form.mobile" placeholder="手机号"></el-input>
                    <hd-error name="mobile"/>
                </el-form-item>
                <el-form-item label="邮箱">
                    <el-input v-model="form.email" placeholder="邮箱"></el-input>
                    <hd-error name="email"/>
                </el-form-item>
                <div>
                    <el-form-item label="商户名称">
                        <el-input v-model="form.approve.merchant_name" placeholder="商户名称"></el-input>
                        <hd-error name="merchant_name"/>
                    </el-form-item>
                    <el-form-item label="类别">
                        <el-input v-model="form.approve.merchant_type" placeholder="类别"></el-input>
                        <hd-error name="merchant_type"/>
                    </el-form-item>
                    <el-form-item label="所属商圈">
                        <el-input v-model="form.approve.merchant_district" placeholder="所属商圈"></el-input>
                        <hd-error name="merchant_district"/>
                    </el-form-item>
                    <el-form-item label="商户海报">
                        <hd-images v-model="form.approve.merchant_poster" placeholder="商户海报"
                                   @updateimage="updateimage"></hd-images>
                        <hd-error name="merchant_poster"/>
                    </el-form-item>
                    <el-form-item label="商户介绍">
                        <el-input v-model="form.approve.merchant_introduce" placeholder="商户介绍"
                                  type="textarea"></el-input>
                        <hd-error name="商户介绍"/>
                    </el-form-item>
                    <el-form-item label="商户文化">
                        <el-input v-model="form.approve.merchant_education" placeholder="商户文化"></el-input>
                        <hd-error name="merchant_education"/>
                    </el-form-item>

                    <el-form-item label="商户联系电话">
                        <el-input v-model="form.approve.merchant_phone" placeholder="商户联系电话"></el-input>
                        <hd-error name="merchant_phone"/>
                    </el-form-item>

                    <el-form-item label="商户地址">
                        <el-input v-model="form.approve.merchant_address" placeholder="商户地址"></el-input>
                        <hd-error name="merchant_address"/>
                    </el-form-item>

                    <el-form-item label="经纬度">
                        <hd-coordinates ref="coordinates"
                                        v-model="form.approve.merchant_latitudeAndLongitude"></hd-coordinates>
                        <hd-error name="merchant_latitudeAndLongitude"/>
                    </el-form-item>
                </div>


            </el-card>

        </el-form>
        <el-button-group class="mt-3">
            <el-button type="success" @click="agree">同意</el-button>
            <el-button type="danger" @click="reject">驳回</el-button>
        </el-button-group>

    </div>
</template>

<script>
import tabs from './tabs'

export default {
    route: {path: '/admin/user/:id/judgment'},
    props: ['id'],
    data() {
        return {
            tabs,
            form: {
                approve:
                    {
                        merchant_latitudeAndLongitude: [116.3881, -39.9075],
                        merchant_poster: []
                    }
            },
            uid: this.$route.params.id
        }
    },
    async created() {
        if (this.id) this.form = await this.axios.get(`user/${this.id}`)
    },
    methods: {
        updateimage(file) {
            this.form.approve.merchant_poster = file
        },
        async agree() {
            await this.axios.put(`user/${this.uid}/agree`, this.form)
        },
        async  reject() {
            await this.axios.put(`user/${this.uid}/reject`, this.form)
        },
        async onSubmit() {
            const url = this.id ? `user/${this.id}` : `user`
            await this.axios[this.id ? 'put' : 'post'](url, this.form)
            this.$router.push({name: 'admin.user.normal'});
        }
    }
}
</script>

<style>

</style>
